<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>版本信息编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/web/res/css/xadmin.css">
    <link rel="stylesheet" href="/web/res/wangEditor/wangEditor.css">
    <script src="/web/res/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/web/res/js/xadmin.js"></script>


</head>

<body style="background-color: white;">
    <div class="layui-fluid" id="orderEdit">
        <form class="layui-form layui-form-pane" id="formsubmit" style="width: 500px;margin:20px auto" action="/gs/dzpGuizeSave">




            <div id="editor" style="width: 135%;">
            </div>



            <br>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn layui-btn-radius antiClick" lay-submit lay-filter="save" >&emsp;保存&emsp;</button>
                    <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" onclick="xadmin.close()">&emsp;返回&emsp;</button>
                </div>
            </div>
        </form>
        <input id="imageUrl" name="imageUrl" value="" type="hidden">
    </div>
    <script type="text/javascript" src="/web/res/wangEditor/wangEditor.js"></script>
    <script>
        layui.use('form', function () {
            let $ = layui.$;
            var form = layui.form;
            form.render();

            $.fn.extend({
                serializeObject: function() {
                    var obj = {}; //声明一个对象
                    $.each(this.serializeArray(), function(index, field) {
                        obj[field.name] = field.value; //通过变量，将属性值，属性一起放到对象中
                    })
                    return obj;
                }
            });


            form.on('submit('+$("button[lay-submit]:eq(0)").attr("lay-filter")+')', function(data){
                layer.confirm('确认要保存吗？', function (index) {

                    var str=editor.txt.html();

                    $(".antiClick").attr("disabled",true);

                    $.ajax({
                        type: "POST",
                        url: "/gs/dzpGuizeSave",
                        data: {
                            dzpGuize: str.replace(/<img/g, '<img style="max-width: 100%;"')
                        },
                        dataType: "json",
                        success: function (data) {//data：返回数据（json对象）
                            if (data.code == 200) {
                                layer.msg(data.msg, {icon: 1, time: 2000});
                            } else{
                                layer.msg(data.msg, {icon: 2, time: 2000});
                            }
                            setTimeout(function () {
                                parent.location.reload();
                            }, 2000);
                            $(".antiClick").attr("disabled",false);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {

                        }


                });

                });

            });


        });

        var E = window.wangEditor
        var editor = new E('#editor')
        /*editor.customConfig.uploadImgServer = '/gs/helpUpload';
        editor.customConfig.uploadFileName = 'myFileName';

        editor.customConfig.uploadImgHooks = {
            before: function(xhr, editor, files) {
            },
            success: function(xhr, editor, result) {
                var num=$("#graphics").val();
                $("#graphics").val("");
                $("#graphics").val(parseInt(num)+1);
                var url=$("#imageUrl").val();
                console.log(url);
                console.log(url=='');
                if(url==''){
                    $("#imageUrl").val(result.data[0]);
                }else{
                    $("#imageUrl").val(url+","+result.data[0]);
                }
                console.log("上传成功");
            },
            fail: function(xhr, editor, result) {

                console.log("上传失败,原因是" + result);
            },
            error: function(xhr, editor) {
                console.log("上传出错");
            },
            timeout: function(xhr, editor) {
                console.log("上传超时");
            }
        };*/
        editor.create();
        editor.txt.html('${dzpGuize!''}');

    </script>
</body>

</html>